<?php
class DetailController extends HomeController{
	
	public function filters(){
		return array(
				array(
						'system.web.widgets.COutputCache',
						'duration'=>24*60*60,
						'varyByParam'=>array('article_id')
				)
		);
	}
	
	public function actionIndex($article_id){
		$aid = intval($article_id);
		if($aid <= 0){
			$this->error('错误的ID号');
		}
		
		$article = Article::model();
		$article = $article->findByPk($aid);

		$article->updateByPk($aid, array('click'=>($article->click)+1));
		
		//创建查询条件
		$cdb = new CDbCriteria();
		$cdb->condition = 'category_id = '.$article->category_id;
		$cdb->limit = 10;
		$relations = Article::model()->findAll($cdb);
		
		//获取栏目信息
		$cateInfo = Category::model()->findByPk($article->category_id);
		
		$this->_title = $article->title . '-' . Yii::app()->name;
		$this->_keywords = $article->keywords . '-' . Yii::app()->name;
		$this->_description = $article->description;
		
		$data = array(
				'article'=>$article,
				'relations'=>$relations,
				'cateInfo'=>$cateInfo
		);

		$this->render('index', $data);
	}
}